package com.ssm.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.springboot.dao.QfTeachDao;
import com.ssm.springboot.pojo.DataInfo;
import com.ssm.springboot.pojo.QfTeach;
import com.ssm.springboot.service.QfTeachService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (QfTeach)表服务实现类
 *
 * @author makejava
 * @since 2021-12-23 15:22:59
 */
@Service
public class QfTeachServiceImpl implements QfTeachService {
    @Resource
    private QfTeachDao qfTeachDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DataInfo queryById(Integer id) {
        QfTeach qfTeach = qfTeachDao.queryById(id);
        return new DataInfo(0,null,null,qfTeach);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     * @param page
     * @param limit
     */
    @Override
    public DataInfo queryAllByLimit(int page, int limit) {
        PageHelper.startPage(page,limit);
        List<QfTeach> teaches = qfTeachDao.queryAllByLimit();
        PageInfo<QfTeach> qfTeachPageInfo = PageInfo.of(teaches);
        return new DataInfo(0,"查询成功",qfTeachPageInfo.getTotal(),qfTeachPageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param qfTeach 实例对象
     * @return 实例对象
     */
    @Override
    public DataInfo insert(QfTeach qfTeach) {
        qfTeach.setCreatetime(new Date());
        qfTeachDao.insert(qfTeach);
        return new DataInfo(0,null,null,null);
    }

    /**
     * 修改数据
     *
     * @param qfTeach 实例对象
     * @return 实例对象
     */
    @Override
    public DataInfo update(QfTeach qfTeach) {
        qfTeach.setUpdatetime(new Date());
        qfTeachDao.update(qfTeach);
        return new DataInfo(0,null,null,null);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public DataInfo deleteById(Integer id) {
        return null;
    }

    @Override
    public DataInfo delete(int id) {
        qfTeachDao.deleteById(id);
        return new DataInfo(0,null,null,null);
    }
}